﻿using B.S.DataBase.MyProject.Domain.Vendors;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.VendorsCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.VendorsCommandHandler
{
    /// <summary>
    /// 原料供品表查询
    /// </summary>
    public class SuppliCommandHandler : IRequestHandler<SuppliCommand, APIResult<List<Supplieditems>>>
    {

        /// <summary>
        /// 原料供品表
        /// </summary>
        private readonly IBaseRepository<Supplieditems> suppbaseRepository;

        public SuppliCommandHandler(IBaseRepository<Supplieditems> suppbaseRepository)
        {
            this.suppbaseRepository = suppbaseRepository;
        }

        public Task<APIResult<List<Supplieditems>>> Handle(SuppliCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Supplieditems>> result = new APIResult<List<Supplieditems>>();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();

            var list = suppbaseRepository.GetAll().Result;

            result.data = list.ToList();


            return Task.FromResult(result);

        }
    }
}
